package org.ihelpuoo.util;

import org.ihelpuoo.lang.StringUtils;

public abstract class ValueSet
{
	public abstract Object get(String key);

	public String getString(String key)
	{
		Object obj = get(key);
		if (null != obj)
			return obj.toString();
		return null;
	}

	public String getStringTrimed(String key)
	{
		return StringUtils.trim(getString(key));
	}

	public int getInt(String key)
	{
		Object obj = getStringTrimed(key);
		if (null != obj)
			if (obj instanceof Integer)
				return ((Integer)obj).intValue();
			else
				return Integer.parseInt(obj.toString());
		return -1;
	}

	public float getFloat(String key)
	{
		Object obj = getStringTrimed(key);
		if (null != obj)
			if (obj instanceof Float)
				return ((Float)obj).floatValue();
			else
				return Float.parseFloat(obj.toString());
		return -1;
	}

	public boolean getBoolean(String key)
	{
		Object obj = getStringTrimed(key);
		if (null != obj)
			if (obj instanceof Float)
				return ((Boolean)obj).booleanValue();
			else
				return Boolean.parseBoolean(obj.toString());
		return false;
	}

	public long getLong(String key)
	{
		Object obj = getStringTrimed(key);
		if (null != obj)
			if (obj instanceof Float)
				return ((Long)obj).longValue();
			else
				return Long.parseLong(obj.toString());
		return -1L;
	}

	public double getDouble(String key)
	{
		Object obj = getStringTrimed(key);
		if (null != obj)
			if (obj instanceof Float)
				return ((Double)obj).doubleValue();
			else
				return Double.parseDouble(obj.toString());
		return -1;
	}

	public boolean contains(String key)
	{
		return null != get(key);
	}
}
